home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 4.0 KB | 141 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWSUBuff.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWSUBUFF_H
- #define FWSUBUFF_H
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // class FW_CStorageUnitBuffer
- //
- // This class implements a buffer for use with FW_CStorageUnitSink. Each call to
- // FW_CStorageUnitSink::Read() results in the creation and destruction of an
- // intermediate FW_CByteArray. To eliminate some of the expense associated with
- // that operation, ReadPeek() and WritePeek() methods of FW_CStorageUnitSink use
- // this class to allow the buffering of data being read and/or written to/from
- // a storage unit.
- //
- // Note that none of the methods of this class actually do any reading or writing.
- // The FW_CStorageUnitSink instance must obtain a pointer to the buffer in memory
- // and fill it with data. This class is responsible only for maintaining the
- // buffer and data pertaining directly to it.
- //
- // This is an implementation class, and it should be considered private to
- // FW_CStorageUnitSink.
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CStorageUnitBuffer FW_AUTO_DESTRUCT_OBJECT
- {
- public:
-
- enum {
- kDefaultCapacity = 1024
- };
-
- enum EBufferKind {
- kInvalid,
- kReadPeek,
- kWritePeek
- };
-
- // ----- Constructors, destructor, operators -----
-
- FW_CStorageUnitBuffer(long fCapacity = kDefaultCapacity);
- FW_CStorageUnitBuffer(const FW_CStorageUnitBuffer& otherBuffer);
-
- ~FW_CStorageUnitBuffer();
-
- FW_CStorageUnitBuffer& operator=(const FW_CStorageUnitBuffer&);
-
- // ----- Getters & setters -----
-
- char* GetAddress();
- long GetCapacity();
- long GetPosition();
- long GetInitialPosition();
- FW_Boolean IsDirty();
-
- // ----- Buffer-management routines -----
-
- void Initialize(EBufferKind kind, long validBytes = 0, long filePosition = 0);
-
- const void* ReadPeek(long& availableReadBytes);
- void ReadPeekAdvance(long bytesRead);
-
- void* WritePeek(long& availableWriteBytes);
- void WritePeekAdvance(long bytesWritten);
-
- private:
-
- char* fBuffer;
- long fCapacity;
- long fValidBytes;
- long fPosition;
- long fType;
- long fInitialPosition;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::GetAddress
- //----------------------------------------------------------------------------------------
-
- inline char* FW_CStorageUnitBuffer::GetAddress()
- {
- return fBuffer;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::GetCapacity
- //----------------------------------------------------------------------------------------
-
- inline long FW_CStorageUnitBuffer::GetCapacity()
- {
- return fCapacity;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::GetPosition
- //----------------------------------------------------------------------------------------
-
- inline long FW_CStorageUnitBuffer::GetPosition()
- {
- return fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::GetInitialPosition
- //----------------------------------------------------------------------------------------
-
- inline long FW_CStorageUnitBuffer::GetInitialPosition()
- {
- return fInitialPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::IsDirty
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CStorageUnitBuffer::IsDirty()
- {
- return fType == kWritePeek && fPosition != 0;
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-